// 代码块 importM
import 'package:flutter/material.dart';
import './pages/tabs.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false, // 去掉debugger图标
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;

  // 生命周期函数：当组件初始化时出发
  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 9, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading:
            IconButton(onPressed: () {}, icon: const Icon(Icons.menu)), // 左侧的按钮
        backgroundColor: Colors.red,
        title: const Text("Flutter app"),
        actions: [
          IconButton(onPressed: () {}, icon: const Icon(Icons.search)),
          IconButton(onPressed: () {}, icon: const Icon(Icons.more_horiz)),
        ], // 右侧的按钮
        bottom: TabBar(
            isScrollable: true, // 是否可以滚动
            indicatorColor: Colors.white, // 指示器颜色
            indicatorPadding: const EdgeInsets.all(5), // // 指示器Padding
            labelColor: Colors.yellow, // 选中颜色
            unselectedLabelColor: Colors.white, // 未选中颜色
            controller: _tabController, // 注意：配置controller需要去掉 TabBar的const
            tabs: const [
              Tab(
                child: Text("关注"),
              ),
              Tab(
                child: Text("热门"),
              ),
              Tab(
                child: Text("视频"),
              ),
              Tab(
                child: Text("关注2"),
              ),
              Tab(
                child: Text("热门2"),
              ),
              Tab(
                child: Text("视频3"),
              ),
              Tab(
                child: Text("关注3"),
              ),
              Tab(
                child: Text("热门3"),
              ),
              Tab(
                child: Text("视频3"),
              ),
            ]),
      ),
      body: TabBarView(controller: _tabController, children: [
        ListView(
          children: const [ListTile(title: Text("我是关注列表"))],
        ),
        ListView(
          children: const [ListTile(title: Text("我是热门列表"))],
        ),
        ListView(
          children: const [ListTile(title: Text("我是视频列表"))],
        )
      ]),
    );
  }
}
